'use strict'

const Service = require('egg').Service

const jwt = require('jsonwebtoken')

class ActionTokenService extends Service {
  async apply(data, options={}) {
    const { ctx } = this

    options.expiresIn = ctx.app.config.passportJwt.expiresIn

    return jwt.sign({
      username: data.username,
    }, ctx.app.config.passportJwt.secret, options)
  }
}

module.exports = ActionTokenService
